package com.jlcindia.hibernate;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;

import org.hibernate.*;


public class Lab12Client {
	public static void main(String arg[])
	{
		EntityTransaction tx = null;
		try
		{
			EntityManagerFactory factory = JPAUtil.getEntityManagerFactory();
			EntityManager manager = factory.createEntityManager();
			tx = manager.getTransaction();
			tx.begin();

						// 1.Adding students
						Student stu = new Student("sri", "Blore", "Enabled", 15000.0);
						manager.persist(stu);
						

						// 2.Adding current students
						CurrentStudent cstu = new CurrentStudent("vas", "Blore", "Enabled",
								15000.0, 2000.0, "6:30 P.M.", "BTM");
						manager.persist(cstu);
						
						// 3.Adding old students
						OldStudent ostu = new OldStudent("aa", "Blore", "Enabled", 15000.0,
								"SDSoft", "aa@jlc.com", 9.0);
						manager.persist(ostu);

						// 4.Adding regular students
						RegularStudent rstu = new RegularStudent("bb", "Blore", "Enabled",
								15000.0, 2000.0, "6:30 P.M.", "BTM", "M.Sc", "85.5", 3);
						manager.persist(rstu);

						// 5.Adding weekend students
						WeekendStudent wstu = new WeekendStudent("cc", "Blore", "Enabled",
								15000.0, 2000.0, "6:30 P.M.", "HSR", "SDSoft",
								"cc@jlc.com", 9);
						manager.persist(wstu);
			
			tx.commit();
			manager.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
			if(tx!=null)
				tx.rollback();
		}
	}

}
